'use strict'

var fs = require('fs');

var rs = fs.createReadStream('test.txt');
rs.on('data',function(chunk){
    console.log('DATA');
    console.log(chunk);
});
rs.on('end',function() {
    console.log('EDN');
});
rs.on('error',function(err) {
    console.log('ERROR:'+err);
});

var ws = fs.createWriteStream('out.txt','utf-8');
ws.write('Hello');
ws.write(',');
ws.write('World');
ws.end();

var byteWs = fs.createWriteStream('byte.txt');
byteWs.write(new Buffer('Hello','utf-8'));
byteWs.write(new Buffer(',','utf-8'));
byteWs.write(new Buffer('World','utf-8'));
byteWs.end();

rs = fs.createReadStream('test.txt');
ws = fs.createWriteStream('out.txt');

// rs.pipe(ws);
rs.pipe(ws,{ end: false });
ws.write('\n us pipe');
ws.end();